<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="值班名称" prop="name">
        <el-input
          v-model="queryParams.planName"
          placeholder="值班名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始日期" prop="time">
        <el-date-picker
          clearable
          v-model="queryParams.importTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择带班日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期" prop="time">
        <el-date-picker
          clearable
          v-model="queryParams.outTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择带班日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['app:inspection:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['app:inspection:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['app:inspection:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="testhandleList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="值班名称" align="center" prop="planName" />
      <el-table-column label="值班开始时间" align="center" prop="startTime" />
      <el-table-column
        label="值班结束时间"
        align="center"
        prop="endTime"
        width="180"
      />
      <el-table-column
        label="计划值班人员"
        align="center"
        prop="checkPersonName"
      />
      <el-table-column label="创建时间" align="center" prop="createTime" />

      <el-table-column
        label="签到值班人员"
        align="center"
        prop="finalAttendPerson"
        width="220"
      >
        <template slot-scope="scope">
          <el-button
            style="padding: 5px"
            size="mini"
            type="primary"
            @click="showList(scope.row, item)"
            v-for="(item, index) in scope.row.finalAttendPerson"
            :key="index"
            >{{ item.nickName }}</el-button
          >
        </template>
      </el-table-column>
      <!-- <el-table-column label="上传照片" align="center" prop="trainPic" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.trainPic" :width="50" :height="50" />
        </template>
      </el-table-column> -->
      <el-table-column label="值班内容" align="center" prop="checkRecord" />
      <el-table-column
        label="操作"
        align="center"
        width="200px"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-if="getSignin(scope.row) && isHave(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="Signin(scope.row)"
            >签到</el-button
          >
          <el-button
            v-if="isHave(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="workHistort(scope.row)"
            >工作记录</el-button
          >
          <el-button
            v-if="isHave(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="workDiary(scope.row)"
            >值班日志</el-button
          >
          <el-button
            v-if="isHave(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="afterWork(scope.row)"
            >下班签名</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['app:inspection:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['app:inspection:remove']"
            >删除</el-button
          >
          
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改测试对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="值班名称" prop="planName">
          <el-input v-model="form.planName" placeholder="请输入值班名称" />
        </el-form-item>
        <el-form-item label="值班人员" prop="checkPerson">
          <el-select
            v-model="form.checkPerson"
            multiple
            collapse-tags
            filterable
            placeholder="选择人员*输入以搜索"
          >
            <el-option
              v-for="item in userSelectList"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="值班内容" prop="checkRecord">
          <el-input v-model="form.checkRecord" placeholder="请输入值班内容" />
        </el-form-item>
        <el-form-item label="值班开始时间" prop="startTime">
          <el-date-picker
            clearable
            v-model="form.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择值班开始时间"
            default-time="00:00:00"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="值班结束时间" prop="endTime">
          <el-date-picker
            clearable
            v-model="form.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择值班结束时间"
            default-time="00:00:00"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="值班类型" prop="type">
          <el-select v-model="form.type">
            <el-option label="领导值班" :value="1"></el-option>
            <el-option label="部门值班" :value="2"></el-option>
          </el-select>
        </el-form-item> -->

        <!-- <el-form-item label="培训图片" prop="trainPic">
         
          <ImageUpload v-model="form.trainPic" @input="upImage" :limit="1"></ImageUpload>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 签到人员弹框 -->
    <el-dialog :visible.sync="workListShow" width="1600px" append-to-body>
      <div class="head">
        <div>值班工作检查情况记录表</div>
        <div>值班日志</div>
      </div>
      <div class="body">
        <div class="workListTop" style="margin-right: 10px">
          <div class="item title">序号</div>
          <div class="item title">巡查点</div>
          <div class="item title">主要操作规程</div>
          <div class="item title">劳动纪律情况</div>
          <div class="item title">安全生产情况</div>
          <div class="item title twoText">存在问题及处理措施、结果</div>
          <div class="item title">落实情况</div>
          <div class="item title">照片</div>

          <div class="item">1</div>
          <div class="item">选矿厂</div>
          <div class="item">{{ part1.mainProcess | statusFilter }}</div>
          <div class="item">{{ part1.laborSituation | statusFilter }}</div>
          <div class="item">{{ part1.safeDetail | statusFilter }}</div>
          <div class="item">{{ part1.checkResult }}</div>
          <div class="item">{{ part1.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part1.checkPic" :width="100" :height="100" />
          </div>

          <div class="item">2</div>
          <div class="item">尾矿库</div>
          <div class="item">{{ part2.mainProcess | statusFilter }}</div>
          <div class="item">{{ part2.laborSituation | statusFilter }}</div>
          <div class="item">{{ part2.safeDetail | statusFilter }}</div>
          <div class="item">{{ part2.checkResult }}</div>
          <div class="item">{{ part2.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part2.checkPic" :width="100" :height="100" />
          </div>

          <div class="item">3</div>
          <div class="item">计量(地磅)</div>
          <div class="item">{{ part3.mainProcess | statusFilter }}</div>
          <div class="item">{{ part3.laborSituation | statusFilter }}</div>
          <div class="item">{{ part3.safeDetail | statusFilter }}</div>
          <div class="item">{{ part3.checkResult }}</div>
          <div class="item">{{ part3.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part3.checkPic" :width="100" :height="100" />
          </div>

          <div class="item">4</div>
          <div class="item">各检查站</div>
          <div class="item">{{ part4.mainProcess | statusFilter }}</div>
          <div class="item">{{ part4.laborSituation | statusFilter }}</div>
          <div class="item">{{ part4.safeDetail | statusFilter }}</div>
          <div class="item">{{ part4.checkResult }}</div>
          <div class="item">{{ part4.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part4.checkPic" :width="100" :height="100" />
          </div>

          <div class="item">5</div>
          <div class="item">加油站、炸药库</div>
          <div class="item">{{ part5.mainProcess | statusFilter }}</div>
          <div class="item">{{ part5.laborSituation | statusFilter }}</div>
          <div class="item">{{ part5.safeDetail | statusFilter }}</div>
          <div class="item">{{ part5.checkResult }}</div>
          <div class="item">{{ part5.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part5.checkPic" :width="100" :height="100" />
          </div>

          <div class="item">6</div>
          <div class="item">其他</div>
          <div class="item">{{ part6.mainProcess | statusFilter }}</div>
          <div class="item">{{ part6.laborSituation | statusFilter }}</div>
          <div class="item">{{ part6.safeDetail | statusFilter }}</div>
          <div class="item">{{ part6.checkResult }}</div>
          <div class="item">{{ part6.checkDetail }}</div>
          <div class="item">
            <image-preview :src="part6.checkPic" :width="100" :height="100" />
          </div>
        </div>
        <div class="workListTop workListTop2">
          <div class="item title le"></div>
          <div class="item title">起止时间</div>
          <div class="item title">内容</div>
          <div class="item title">处理措施及结果</div>
          <div class="item title">交接事项</div>
          <div class="item title">备注</div>

          <div class="item le">检查站情况</div>
          <div class="item" style="line-height:38px">{{ part7.starStopTime }}</div>
          <div class="item">{{ part7.content }}</div>
          <div class="item">{{ part7.checkResult }}</div>
          <div class="item">{{ part7.exchangeSituation }}</div>
          <div class="item">{{ part7.remark }}</div>

          <div class="item le">巡查点情况</div>
          <div class="item" style="line-height:38px">{{ part8.starStopTime }}</div>
          <div class="item">{{ part8.content }}</div>
          <div class="item">{{ part8.checkResult }}</div>
          <div class="item">{{ part8.exchangeSituation }}</div>
          <div class="item">{{ part8.remark }}</div>

          <div class="item le">监控记录审查情况</div>
          <div class="item" style="line-height:38px">{{ part9.starStopTime }}</div>
          <div class="item">{{ part9.content }}</div>
          <div class="item">{{ part9.checkResult }}</div>
          <div class="item">{{ part9.exchangeSituation }}</div>
          <div class="item">{{ part9.remark }}</div>

          <div class="item bott le">其他</div>
          <div class="item bott" style="line-height:38px">{{ part10.starStopTime }}</div>
          <div class="item bott">{{ part10.content }}</div>
          <div class="item bott">{{ part10.checkResult }}</div>
          <div class="item bott">{{ part10.exchangeSituation }}</div>
          <div class="item bott">{{ part10.remark }}</div>
          <!-- <div class="item bott le">签名</div> -->
          <!-- <div class="item bott">{{ part11.starStopTime }}</div>
          <div class="item bott">{{ part11.content }}</div>
          <div class="item bott">{{ part11.checkResult }}</div>
          <div class="item bott">{{ part11.exchangeSituation }}</div>
          <div class="item bott">{{ part11.remark }}</div> -->
        </div>
        <div class="sign">
          签名:
          <img style="width: 100px; height: 70px" :src="part0.signPic" alt="" />
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" icon="el-icon-download" @click="handleExport()">导 出</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="workHistortShow" width="600px" append-to-body>
      <div class="body">
        <el-form ref="form2" :rules="rules" label-width="120px">
          <el-form-item label="区域">
            <el-select v-model="workForm.checkPart">
              <el-option label="选矿厂" :value="1"></el-option>
              <el-option label="尾矿库" :value="2"></el-option>
              <el-option label="计量(地磅)" :value="3"></el-option>
              <el-option label="各检查站" :value="4"></el-option>
              <el-option label="加油站、炸药库" :value="5"></el-option>
              <el-option label="其他" :value="6"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="主要操作规程">
            <el-select v-model="workForm.mainProcess">
              <el-option label="正常" :value="1"></el-option>
              <el-option label="不正常" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="劳动纪律情况">
            <el-select v-model="workForm.laborSituation">
              <el-option label="正常" :value="1"></el-option>
              <el-option label="不正常" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="安全生产情况">
            <el-select v-model="workForm.safeDetail">
              <el-option label="正常" :value="1"></el-option>
              <el-option label="不正常" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="存在问题及处理结果">
            <el-input v-model="workForm.checkResult" type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="落实情况">
            <el-input v-model="workForm.checkDetail" type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="检查图片">
            <ImageUpload
              v-model="workForm.checkPic"
              @input="workFormupImage"
              :limit="1"
            ></ImageUpload>
          </el-form-item>
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
        <el-button @click="workHistortShow = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="diaryShow" width="500px" append-to-body>
      <div class="body">
        <el-form ref="form3" :rules="rules" label-width="120px">
          <el-form-item label="区域">
            <el-select v-model="dairyForm.checkPart">
              <el-option label="检查站情况" :value="1"></el-option>
              <el-option label="巡查点情况" :value="2"></el-option>
              <el-option label="监控记录审查情况" :value="3"></el-option>
              <el-option label="其他" :value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始时间">
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="00:00:00"
              v-model="dairyForm.importTime"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              default-time="00:00:00"
              v-model="dairyForm.outTime"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="内容">
            <el-input type="textarea" v-model="dairyForm.content"></el-input>
          </el-form-item>
          <el-form-item label="处理措施及结果">
            <el-input
              type="textarea"
              v-model="dairyForm.checkResult"
            ></el-input>
          </el-form-item>
          <el-form-item label="交接事项">
            <el-input v-model="dairyForm.exchangeSituation" type="textarea">
            </el-input>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="dairyForm.remark" type="textarea"> </el-input>
          </el-form-item>

          <!-- <el-form-item label="培训图片" prop="trainPic">
          <ImageUpload v-model="form.trainPic" @input="upImage" :limit="1"></ImageUpload>
        </el-form-item> -->
        </el-form>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dairySubmit">确 定</el-button>
        <el-button @click="workHistortShow = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog title="电子签名" :visible.sync="signLog" width="700px">
      <signinDia @setsignin="setsignin" :fileName="'sign'"></signinDia>
    </el-dialog>
    <el-dialog title="下班签名" :visible.sync="signShow" width="700px">
      <div
        @click="signLog = true"
        style="width: 200px; background-color: #d9d9d9"
      >
        <el-image
          :src="signinimg"
          style="
            width: 200px;
            height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #999;
          "
        >
          <div slot="error">点击签名</div>
        </el-image>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="signSubmit">确 定</el-button>
        <el-button @click="signShow = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deptTreeSelect, listUser } from "@/api/system/user";
import {
  meetingList,
  recordList,
  recordExport,
  inspectionList,
  inspectionAdd,
  inspectionEdit,
  inspectionRemove,
  sitelogList,
  sitedetaildAdd,
  sitelogAdd,
  sitedetaildEdit,
  sitelogEdit,
} from "@/api/system/leaderDuty";
import cache from "@/plugins/cache";
import signinDia from "@/components/signFont/index.vue";

export default {
  name: "Testhandle",
  components: {
    signinDia,
  },
  data() {
    return {
      signShow: false,
      signinimg: null,
      signLog: false,
      workForm: {
        checkPart: 1,
        mainProcess: null,
        laborSituation: null,
        safeDetail: null,
        checkResult: "",
        checkDetail: "",
        checkPic: null,
      },

      dairyForm: {
        checkPart: 1,
        importTime: null,
        outTime: null,
        content: null,
        checkResult: "",
        exchangeSituation: "",
        remark: null,
      },
      signForm: {
        checkPart: 0,
        signPic: null,
      },
      diaryShow: false,
      planId: null,
      workHistortShow: false,
      userId: cache.session.getJSON("userId"),
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试表格数据
      testhandleList: [],
      humData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      humOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planName:null,
        importTime:null,
        outTime:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      deptOptions: [],
      userSelectList: [],
      workListShow: false,
      part1: {},
      part2: {},
      part3: {},
      part4: {},
      part5: {},
      part6: {},
      part7: {},
      part8: {},
      part9: {},
      part10: {},
      part11: {},
      part0: {},
      newUserId:null,
      newPlanId:null
    };
  },
  filters: {
    statusFilter(value) {
      return value == 1 ? "正常" : value == 2 ? "不正常" : "未填";
    },
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询测试列表 */
    getList() {
      this.loading = true;
      inspectionList({ ...this.queryParams, type: 1 }).then((response) => {
        this.testhandleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    workFormupImage() {
      this.workForm.checkPic = e;
    },
    setsignin(img) {
      this.signinimg = img;
      this.signLog = false;
      this.signForm.signPic = img;
    },
    showList(data, item) {
      console.log(data, item);
      this.part1 = {};
      this.part2 = {};
      this.part3 = {};
      this.part4 = {};
      this.part5 = {};
      this.part6 = {};
      this.part7 = {};
      this.part8 = {};
      this.part9 = {};
      this.part10 = {};
      this.part11 = {};
      this.part0 = {};
      this.workListShow = true;

      this.newUserId = parseInt(item.checkPerson)
      this.newPlanId = data.id
      sitelogList({
        userId: item.checkPerson,
        planId: data.id,
        siteType: 3,
      }).then((res) => {
        console.log(res);
        res.rows.forEach((it) => {
          if (it.siteType == 1) {
            switch (it.checkPart) {
              case 1:
                this.part1 = it;
                break;
              case 2:
                this.part2 = it;
                break;
              case 3:
                this.part3 = it;
                break;
              case 4:
                this.part4 = it;
                break;
              case 5:
                this.part5 = it;
                break;
              case 6:
                this.part6 = it;
                break;
              case 0:
                this.part0 = it;
              default:
                break;
            }
          } else if (it.siteType == 2) {
            it.starStopTime = it.importTime + "-" + it.outTime;
            switch (it.checkPart) {
              case 1:
                this.part7 = it;
                break;
              case 2:
                this.part8 = it;
                break;
              case 3:
                this.part9 = it;
                break;
              case 4:
                this.part10 = it;
                break;
            }
          }
        });

      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    look(data) {
      this.humOpen = true;
      recordList({ meetingId: data.id }).then((res) => {
        console.log(res);
        this.humData = res.rows;
      });
    },
    upImage(e) {
      this.form.trainPic = e;
    },
    // 表单重置
    reset() {
      this.form = {
        planName: null,
        startTime: null,
        endTime: null,
        type: 1,
        trainPlace: null,
        checkPerson: null,
        checkRecord: null,
        creatId: this.userId,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 20,
        planName:null
      }
     this.getList()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.getDeptTree();
      this.getUserList();
      this.reset();
      this.open = true;
      this.title = "添加值班信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.getDeptTree();
      this.getUserList();
      this.reset();
      // const id = row.id || this.ids;

      this.open = true;
      this.title = "修改值班信息";
      this.form = { ...row };
      console.log(this.form);
      this.form.checkPerson = this.form.checkPerson.split(",").map(Number);
      console.log(this.form);

      // getTesthandle(id).then((response) => {
      //   this.form = response.data;

      // });
    },
    getCurrentTime() {
      const now = new Date();
      const year = now.getFullYear();
      const month = String(now.getMonth() + 1).padStart(2, "0");
      const day = String(now.getDate()).padStart(2, "0");
      const hours = String(now.getHours()).padStart(2, "0");
      const minutes = String(now.getMinutes()).padStart(2, "0");
      const seconds = String(now.getSeconds()).padStart(2, "0");
      let currentTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;

      return currentTime;
    },
    getSignin(data) {
      let val = data.finalAttendPerson;
      for (let i = 0; i < val.length; i++) {
        if (val[i].checkPerson == this.userId) {
          // console.log("签过了");
          return false;
        }
      }

      return true;
    },
    isHave(data) {
      let idList = data.checkPerson.split(",");
      for (let x = 0; x < idList.length; x++) {
        if (idList[x] == this.userId) {
          // console.log("不用签到");
          return true;
        }
      }
      return false;
    },
    workHistort(data) {
      console.log(data);
      (this.workForm = {
        checkPart: null,
        mainProcess: null,
        laborSituation: null,
        safeDetail: null,
        checkResult: "",
        checkDetail: "",
        checkPic: null,
      }),
        (this.workHistortShow = true);

      this.planId = data.id;
    },
    workDiary(data) {
      console.log(data);
      (this.dairyForm = {
        checkPart: null,
        importTime: null,
        outTime: null,
        content: null,
        checkResult: "",
        exchangeSituation: "",
        remark: null,
      }),
        (this.diaryShow = true);
      this.planId = data.id;
    },
    Signin(data) {
      sitedetaildAdd({
        planId: data.id,
        userId: this.userId,
        registTime: this.getCurrentTime(),
        checkPart: 0,
        status: 1,
      }).then((res) => {
        this.$message({
          message: "签到成功",
          type: "success",
        });
        this.getList();
        // console.log(res);
        // recordAdd({
        //   meetingId: data.id,
        //   userId: this.userId,
        //   signTime: this.getCurrentTime(),
        //   mineId: 1,
        // }).then((res) => {
        //   console.log(res);

        //   this.getList();
        // });
      });

      //
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 查询人员
    getUserList() {
      listUser({
        pageNum: 1,
        pageSize: 999,
      }).then((res) => {
        this.userSelectList = res.rows;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            this.form.checkPerson = this.form.checkPerson.join();
            inspectionEdit(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.checkPerson = this.form.checkPerson.join();
            inspectionAdd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    submit() {
      sitelogList({
        userId: this.userId,
        planId: this.planId,
        siteType: 1,
      }).then((res) => {
        console.log(res);
        let tag = true;
        let id = null;
        let val = res.rows;
        for (let i = 0; i < val.length; i++) {
          if (val[i].checkPart == this.workForm.checkPart) {
            tag = false;
            id = val[i].id;
          }
        }
        if (tag) {
          sitedetaildAdd({
            ...this.workForm,
            planId: this.planId,
            userId: this.userId,
          }).then((res) => {
            console.log(res);
            this.$modal.msgSuccess("提交成功");
            this.workHistortShow = false
            this.getList()
          });
        } else {
          sitedetaildEdit({
            ...this.workForm,
            planId: this.planId,
            userId: this.userId,
            id: id,
          }).then((res) => {
            console.log(res);
            this.$modal.msgSuccess("修改成功");
            
            this.workHistortShow = false
            this.getList()
          });
        }
      });
    },
    dairySubmit() {
      sitelogList({
        userId: this.userId,
        planId: this.planId,
        siteType: 2,
      }).then((res) => {
        console.log(res);
        let tag = true;
        let id = null;
        let val = res.rows;
        for (let i = 0; i < val.length; i++) {
          if (val[i].checkPart == this.dairyForm.checkPart) {
            tag = false;
            id = val[i].id;
          }
        }
        if (tag) {
          sitelogAdd({
            ...this.dairyForm,
            planId: this.planId,
            userId: this.userId,
          }).then((res) => {
            console.log(res);
            this.$modal.msgSuccess("提交成功");
            this.diaryShow = false
            this.getList()
          });
        } else {
          sitelogEdit({
            ...this.dairyForm,
            planId: this.planId,
            userId: this.userId,
            id: id,
          }).then((res) => {
            console.log(res);
            this.$modal.msgSuccess("修改成功");
            this.diaryShow = false
            this.getList()
          });
        }
      });

      // console.log(this.dairyForm);
      // sitelogAdd({
      //   ...this.dairyForm,
      //   planId: this.planId,
      //   userId: this.userId,
      // }).then((res) => {
      //   console.log(res);
      // });
    },
    //签名提交
    signSubmit() {
      sitelogList({
        userId: this.userId,
        planId: this.planId,
        siteType: 1,
      }).then((res) => {
        console.log(res);
        let id = null;
        let val = res.rows;
        for (let i = 0; i < val.length; i++) {
          if (val[i].checkPart == this.signForm.checkPart) {
            id = val[i].id;
          }
        }

        sitedetaildEdit({
          ...this.signForm,
          planId: this.planId,
          userId: this.userId,
          id: id,
        }).then((res) => {
          console.log(res);
          this.$modal.msgSuccess("下班提交成功");
          this.signShow = false
            this.getList()
        });
      });
    },
    afterWork(data) {
      (this.signForm = {
        checkPart: "",
        signPic: null,
      }),
        (this.signShow = true);
      this.planId = data.id;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除测试编号为"' + ids + '"的数据项？')
        .then(function () {
          return inspectionRemove(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport(data) {
      // this.download(
      //   "app/testhandle/export",
      //   {
      //     ...this.queryParams,
      //   },
      //   `testhandle_${new Date().getTime()}.xlsx`
      // );
      
      recordExport({ userId: this.newUserId,planId:this.newPlanId }).then((res) => {
        console.log(res);
        if (res.data != '') {
          window.open(res.data)
        }else {
          this.$message({
          showClose: true,
          message: '请填写完整后导出',
          type: 'warning'
        });
        }
      });
    },
    cascaderChange(data) {
      console.log(data);
      this.form.depart = data;
    },
  },
};
</script>
<style lang="scss" scoped>
.workListTop {
  display: grid;
  width: 50%;
  // padding: 8px 18px;
  grid-template-columns: 40px 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  grid-gap: 0px;
  grid-template-rows: 60px 100px 100px 100px 100px 100px 100px;
  border-left: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  .item {
    // background-color: #ccc;
    border-right: 1px solid #ccc;
    border-top: 1px solid #ccc;
    text-align: center;
    line-height: 100px;
    overflow: hidden;
  }
  .title {
    color: #000;
    font-weight: 700;
    line-height: 60px;
  }
  .twoText {
    line-height: 16px;
    display: flex;
    align-items: center;
  }
}
.workListTop2 {
  grid-template-columns: 90px 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 60px 100px 100px 100px 100px;
  border-bottom: 0;
  border-left: 0;

  .bott {
    border-bottom: 1px solid #ccc;
  }
  .le {
    border-left: 1px solid #ccc;
  }
}
.workListTop3 {
  width: 100%;
  grid-template-columns: 30px 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
  grid-template-rows: 60px 100px 100px 100px 100px;
  .item {
    .el-input--medium {
      height: 100%;
      .el-textarea__inner {
        height: 100% !important;
      }
    }
  }
}
.head,
.body {
  display: flex;
  justify-content: space-between;
  position: relative;
  .el-form {
    width: 100%;
  }
}
.head {
  div {
    width: 50%;
    text-align: center;
    font-size: 20px;
    font-weight: 700;

    color: #000;
  }
}
.sign {
  position: absolute;
  right: 520px;
  top: 550px;
  display: flex;
  justify-content: center;
  img {
    margin-left: 10px;
  }
}
</style>